import request from '@/utils/request'
import { react } from '@/utils/request'

//*********************************设备增删改查******************************************
// 分页查询设备列表
export function listDevice(query) {
  return request({
    url: '/iot/device/list',
    method: 'get',
    params: query
  })
}

// 无分页查询设备列表
export function queryDevice(query) {
  return request({
    url: '/iot/device/query',
    method: 'get',
    params: query
  })
}

// 查询设备详细
export function getDevice(id) {
  return request({
    url: '/iot/device/' + id,
    method: 'get'
  })
}

// 根据产品id获取设备信息
export function getDeviceCache(productId) {
  return request({
    url: '/iot/device/cache/' + productId,
    method: 'get'
  })
}

// 获取指定ID设备详情
export function getDeviceDetailInfo(deviceId) {
  return request({
    url: '/iot/device/detail/' + deviceId,
    method: 'get'
  })
}

// 根据条件获取设备数量
export function getDeviceCount(query) {
  return request({
    url: '/iot/device/count/',
    method: 'get',
    params: query
  })
}

// 新增设备
export function addDevice(data) {
  return request({
    url: '/iot/device',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateDevice(data) {
  return request({
    url: '/iot/device',
    method: 'put',
    data: data
  })
}

// 删除设备
export function delDevice(ids) {
  return request({
    url: '/iot/device/' + ids,
    method: 'delete'
  })
}

//*********************************子设备******************************************

// 分页查询未绑定的子设备列表
export function listChildrenDevice(query) {
  return request({
    url: '/iot/device/children/list',
    method: 'get',
    params: query
  })
}

// 绑定设备
export function bindChildrenDevice(ids, parentId) {
  return request({
    url: '/iot/device/children/bind/' + parentId,
    method: 'put',
    data: ids
  })
}

// 解绑设备
export function unbindChildrenDevice(ids) {
  return request({
    url: '/iot/device/children/unbind/' + ids,
    method: 'delete'
  })
}


//*********************************设备状态****************************************

// 同步全部设备状态
export function syncAllDeviceState() {
  return request({
    url: '/iot/device/state/syncAll',
    method: 'put'
  })
}

// 同步设备状态
export function syncDeviceState(ids) {
  return request({
    url: '/iot/device/state/sync/' + ids,
    method: 'put'
  })
}

// 启用
export function deployDevice(ids) {
  return request({
    url: '/iot/device/state/deploy/' + ids,
    method: 'put'
  })
}

// 启用全部
export function deployAllDevice() {
  return request({
    url: '/iot/device/state/deployAll',
    method: 'put'
  })
}

// 禁用
export function undeployDevice(id) {
  return request({
    url: '/iot/device/state/undeploy/' + id,
    method: 'delete'
  })
}

// 断开连接
export function disconnectDevice(id) {
  return request({
    url: '/iot/device/state/disconnect/' + id,
    method: 'delete'
  })
}


//*********************************设备标签****************************************

// 新增标签
export function addTags(data) {
  return request({
    url: '/iot/device/tags/addBatch',
    method: 'post',
    data: data
  })
}

// 修改标签
export function editTags(data) {
  return request({
    url: '/iot/device/tags',
    method: 'put',
    data: data
  })
}

// 删除标签
export function removeTags(id) {
  return request({
    url: '/iot/device/tags/' + id,
    method: 'delete'
  })
}

// 查询标签列表
export function listTags(query) {
  return request({
    url: '/iot/device/tags/list',
    method: 'get',
    params: query
  })
}

// 无分页查询标签列表
export function queryTags(query) {
  return request({
    url: '/iot/device/tags/query',
    method: 'get',
    params: query
  })
}

//*********************************设备属性****************************************
// 获取设备实时属性
export function getDeviceRealtimeProperty(deviceId, propertyId, headers) {
  return react({
    url: '/iot/device/properties/realtime/' + deviceId + '/' + propertyId,
    method: 'get',
    params: headers
  })
}
// 批量获取设备实时属性
export function getDeviceRealtimeProperties(deviceId, props) {
  return react({
    url: '/iot/device/properties/realtime/' + deviceId,
    method: 'get',
    params: props
  })
}

// 发送设置属性指令到设备
export function setDeviceProperties(deviceId, props) {
  return react({
    url: '/iot/device/properties/setting/' + deviceId,
    method: 'post',
    data: props
  })
}

// 获取指定ID设备最新的全部属性
export function getDeviceLatestProperties(deviceId) {
  return request({
    url: '/iot/device/properties/latest/' + deviceId,
    method: 'get'
  })
}

// 查询设备指定属性列表
export function getDeviceHistoryProperties(deviceId, propertyId, props) {
  return request({
    url: '/iot/device/properties/history/' + deviceId + '/' + propertyId,
    method: 'get',
    params: props
  })
}

//*********************************设备功能****************************************
// 设备功能调用
export function invokedFunction(deviceId, functionId, props) {
  return react({
    url: '/iot/device/functions/' + deviceId + '/' + functionId,
    method: 'post',
    data: props
  })
}

//*********************************发送消息****************************************
// 发送消息
export function sendMessage(deviceId, props) {
  return react({
    url: '/iot/device/message/' + deviceId,
    method: 'post',
    data: props
  })
}
// 发送消息
export function sendMessages(props) {
  return react({
    url: '/iot/device/message/' + deviceId,
    method: 'post',
    data: props
  })
}

//*********************************设备事件****************************************
// 查询设备事件数据
export function queryDeviceEvents(deviceId, eventId, props) {
  return request({
    url: '/iot/device/events/history/' + deviceId + '/' + eventId,
    method: 'get',
    params: props
  })
}

//*********************************设备日志****************************************
// 分页查询设备日志列表
export function listLog(deviceId, query) {
  return request({
    url: '/iot/device/logs/' + deviceId,
    method: 'get',
    params: query
  })
}

//*********************************设备认证配置****************************************

// 重置设备认证配置
export function updateConfiguration(deviceId, configuration) {
  return request({
    url: '/iot/device/configuration/' + deviceId,
    method: 'put',
    data: configuration
  })
}


// 重置设备认证配置
export function resetConfiguration(deviceId) {
  return request({
    url: '/iot/device/configuration/reset/' + deviceId,
    method: 'put'
  })
}

//*********************************设备物模型****************************************

// 获取物模型
export function getMetadata(deviceId) {
  return request({
    url: '/iot/device/metadata/' + deviceId,
    method: 'get'
  })
}

// 更新设备物模型，更新后脱离产品物模型
export function updateMetadata(deviceId, metadata) {
  return request({
    url: '/iot/device/metadata/' + deviceId,
    method: 'put',
    data: metadata
  })
}

// 重置设备物模型
export function resetMetadata(deviceId) {
  return request({
    url: '/iot/device/metadata/' + deviceId,
    method: 'delete'
  })
}


//*********************************协议支持****************************************
// 更新协议支持
export function updateProtocolStandby(deviceId, configuration) {
  return request({
    url: '/iot/device/protocol-standby/' + deviceId,
    method: 'put',
    data: configuration
  })
}


// 重置设备协议支持
export function resetProtocolStandby(deviceId) {
  return request({
    url: '/iot/device/protocol-standby/' + deviceId,
    method: 'delete'
  })
}

//*********************************协议支持****************************************
